package com.huhu.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huhu.dao.ArticleMapper;
import com.huhu.pojo.Article;
import com.huhu.response.Response;
import com.huhu.service.IArticleService;

@Service("iArticleService")
public class ArticleServiceImpl implements IArticleService{
	
	@Autowired
	private ArticleMapper articleMapper;

	@Override
	public Response<Article> selectArticle(Integer date) {
		Article article = articleMapper.selectByPrimaryKey(date);
		if(article ==null) {
			return Response.searchByerror("查询日期不正确或者未输入查询条件！");
		}
		return Response.searchBysuccess(article);
	}

	@Override
	public Response<Article> deleteArticle(Integer date) {
       int result = articleMapper.deleteByPrimaryKey(date);
       if(result<=0) {
    	   return Response.searchByerror("删除出错，删除条件不正确或者未输入删除条件！");
       }

		return Response.searchBysucessMessage("删除成功！");
	}

	public Response<Article> updateArticle(Article article) {
		int result =articleMapper.updateByPrimaryKey(article);
		if(result<=0) {
	    	   return Response.searchByerror("更新出错，更新条件不正确或者未输入更新条件！");
	       }

			return Response.searchBysucessMessage("更新成功！");
	}

	@Override
	public Response<Article> insertArticle(Article article) {
		int result =articleMapper.insert(article);
		if(result<=0) {
	    	   return Response.searchByerror("插入出错，插入条件不正确或者未输入插入条件！");
	       }

			return Response.searchBysucessMessage("插入成功！");
		
	}
    
}
